import React, { Component } from 'react';
import './discuss.css';
import { Tabs, WhiteSpace } from 'antd-mobile';
import Search from './Search'
import GotoPage from './GotoPage';
import GotoPage2 from './GotoPage2';
import GotoPage3 from './GotoPage3';
import GotoPage4 from './GotoPage4';
import GotoPage5 from './GotoPage5';
import { withRouter } from "react-router-dom";
import { ReportCreator, DelReport } from '../Redux/ActionCreator';
import { connect } from 'react-redux';
import { Send_tim } from '../IM/actiontim';
const tabs = [
    { title: '举报商品' },
    { title: '举报动态' },
    { title: '举报用户' },
    { title: '举报商家' },
    { title: '举报评论' }
];
//举报管理右半部分页面
class Discuss extends Component {
    constructor(props) {
        super(props);
        this.state = {
        };
        this.props.dispatch(ReportCreator())
    }
    render() {
        return (
            <div className="body_right">
                <div className='right_top'>
                    <p>举报管理</p>
                </div>
                <div className='right_middle'>
                    <WhiteSpace />
                    <Tabs tabs={tabs} initialPage={0} animated={true} useOnPan={false} tabBarUnderlineStyle={true}>
                        {/* 1. 举报商品 */}
                        <div className='search'>
                            <p>输入查找的内容</p>
                            <Search />
                            <div className='reporttable'>
                                <table border='0' cellpadding='5' cellspacing='0' className='mytable' width="100%">
                                    <thead>
                                        <tr>
                                            <th>编号</th>
                                            <th>ID</th>
                                            <th>举报内容</th>
                                            <th>举报者ID</th>
                                            <th>举报者昵称</th>
                                            <th>举报者电话</th>
                                            <th>被举报商家ID</th>
                                            <th>被举报商品ID</th>
                                            <th>被举报商品名称</th>
                                            <th>被举报商品价钱</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {
                                            // this.props.reportreducer.map((item, index) => {
                                            //     if (item.report2 === 1) {
                                            this.props.reportreducer.filter(
                                                item => !(item.report2 !== 1)).map((item, index) => {
                                                    console.log(item)
                                                    return (
                                                        <tr>
                                                            <td>{index + 1}</td>
                                                            <td>{item.report_id}</td>
                                                            <td>{item.report_context}</td>
                                                            <td>{item.user_id}</td>
                                                            <td>{item.user_name}</td>
                                                            <td>{item.user_phone}</td>
                                                            <td>{item.report.business_id}</td>
                                                            <td>{item.report.commodity_id}</td>
                                                            <td>{item.report.commodity_title}</td>
                                                            <td>{item.report.commodity_money}</td>
                                                            <td>
                                                                <button className="solute"
                                                                    onClick={() => {
                                                                        const adminpwd = prompt('请输入管理员登录密码：')
                                                                        if (adminpwd) {
                                                                            this.props.dispatch(DelReport(item.report_id, adminpwd))
                                                                            Send_tim(item.user_phone, `您举报的商品<${item.report.commodity_title}>已被处理`)
                                                                            let res = this.props.fruiterreducer.filter((item2) => {
                                                                                return item.report.business_id == item2.business_id
                                                                            })
                                                                            Send_tim(res[0].business_phone, `您的商品<${item.business_title}>被举报，已被客服处理`)
                                                                        }
                                                                        return false;
                                                                    }}
                                                                >已解决</button></td>
                                                        </tr>
                                                    )
                                                    //}
                                                })
                                        }
                                    </tbody>
                                </table>
                            </div>
                            {/* 分页 */}
                            <GotoPage />
                        </div>
                        {/* 2. 举报动态 */}
                        <div className='search'>
                            <p>输入查找的内容</p>
                            <Search />
                            <div className='reporttable'>
                                <table border='0' cellpadding='5' cellspacing='0' className='mytable2' width="100%">
                                    <thead>
                                        <tr>
                                            <th>编号</th>
                                            <th>ID</th>
                                            <th>举报内容</th>
                                            <th>举报者ID</th>
                                            <th>举报者昵称</th>
                                            <th>举报者电话</th>
                                            <th>被举报动态ID</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {
                                            this.props.reportreducer.filter(
                                                item => !(item.report2 !== 2)).map((item, index) => {
                                                    console.log(item)
                                                    return (
                                                        <tr>
                                                            <td>{index + 1}</td>
                                                            <td>{item.report_id}</td>
                                                            <td>{item.report_context}</td>
                                                            <td>{item.user_id}</td>
                                                            <td>{item.user_name}</td>
                                                            <td>{item.user_phone}</td>
                                                            <td>{item.report.dynamic_id}</td>
                                                            <td>
                                                                <button className="solute"
                                                                    onClick={() => {
                                                                        const adminpwd = prompt('请输入管理员登录密码：')
                                                                        if (adminpwd) {
                                                                            this.props.dispatch(DelReport(item.report_id, adminpwd))
                                                                            let res = this.props.textreducer.filter((item2) => {
                                                                                return item2.dynamic_id == item.report.dynamic_id
                                                                            })
                                                                            Send_tim(item.user_phone, `您举报的动态<${res[0].dynamic_context}>已经被处理`)
                                                                        }
                                                                        return false;
                                                                    }}
                                                                >已解决</button></td>
                                                        </tr>
                                                    )

                                                })
                                        }
                                    </tbody>
                                </table>
                            </div>
                            {/* 分页 */}
                            <GotoPage2 />
                        </div>
                        {/* 3. 举报用户 */}
                        <div className='search'>
                            <p>输入查找的内容</p>
                            <Search />
                            <div className='reporttable'>
                                <table border='0' cellpadding='5' cellspacing='0' className='mytable3' width="100%">
                                    <thead>
                                        <tr>
                                            <th>编号</th>
                                            <th>ID</th>
                                            <th>举报内容</th>
                                            <th>举报者ID</th>
                                            <th>举报者昵称</th>
                                            <th>举报者电话</th>
                                            <th>被举报用户ID</th>
                                            <th>被举报用户昵称</th>
                                            <th>被举报用户电话</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {
                                            this.props.reportreducer.filter(
                                                item => !(item.report2 !== 3)).map((item, index) => {
                                                    console.log(item)
                                                    return (
                                                        <tr>
                                                            <td>{index + 1}</td>
                                                            <td>{item.report_id}</td>
                                                            <td>{item.report_context}</td>
                                                            <td>{item.user_id}</td>
                                                            <td>{item.user_name}</td>
                                                            <td>{item.user_phone}</td>
                                                            <td>{item.report.user_id}</td>
                                                            <td>{item.report.user_name}</td>
                                                            <td>{item.report.user_phone}</td>
                                                            <td>
                                                                <button className="solute"
                                                                    onClick={() => {
                                                                        const adminpwd = prompt('请输入管理员登录密码：')
                                                                        if (adminpwd) {
                                                                            this.props.dispatch(DelReport(item.report_id, adminpwd))
                                                                        }
                                                                        return false;
                                                                    }}
                                                                >已解决</button></td>
                                                        </tr>
                                                    )

                                                })
                                        }
                                    </tbody>
                                </table>
                            </div>
                            {/* 分页 */}
                            <GotoPage3 />
                        </div>
                        {/* 4. 举报商家 */}
                        <div className='search'>
                            <p>输入查找的内容</p>
                            <Search />
                            <div className='reporttable'>
                                <table border='0' cellpadding='5' cellspacing='0' className='mytable4' width="100%">
                                    <thead>
                                        <tr>
                                            <th>编号</th>
                                            <th>ID</th>
                                            <th>举报内容</th>
                                            <th>举报者ID</th>
                                            <th>举报者昵称</th>
                                            <th>举报者电话</th>
                                            <th>被举报商家ID</th>
                                            <th>被举报商家名称</th>
                                            <th>被举报商家电话</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {
                                            this.props.reportreducer.filter(
                                                item => !(item.report2 !== 4)).map((item, index) => {
                                                    console.log(item)
                                                    return (
                                                        <tr>
                                                            <td>{index + 1}</td>
                                                            <td>{item.report_id}</td>
                                                            <td>{item.report_context}</td>
                                                            <td>{item.user_id}</td>
                                                            <td>{item.user_name}</td>
                                                            <td>{item.user_phone}</td>
                                                            <td>{item.report.business_id}</td>
                                                            <td>{item.report.business_name}</td>
                                                            <td>{item.report.business_phone}</td>
                                                            <td>
                                                                <button className="solute"
                                                                    onClick={() => {
                                                                        const adminpwd = prompt('请输入管理员登录密码：')
                                                                        if (adminpwd) {
                                                                            this.props.dispatch(DelReport(item.report_id, adminpwd))
                                                                            let res = this.props.fruiterreducer.filter((item2) => {
                                                                                return item2.business_id == item.report.business_id
                                                                            })
                                                                            Send_tim(item.user_phone, `您举报的商家<${res[0].business_name}>已被处理`)
                                                                            Send_tim(res[0].business_phone, `您因为<${item.report_context}>被举报`)
                                                                        }
                                                                        return false;
                                                                    }}
                                                                >已解决</button></td>
                                                        </tr>
                                                    )

                                                })
                                        }
                                    </tbody>
                                </table>
                            </div>
                            {/* 分页 */}
                            <GotoPage4 />
                        </div>
                        {/* 5. 举报评论 */}
                        <div className='search'>
                            <p>输入查找的内容</p>
                            <Search />
                            <div className='reporttable'>
                                <table border='0' cellpadding='5' cellspacing='0' className='mytable5' width="100%">
                                    <thead>
                                        <tr>
                                            <th>编号</th>
                                            <th>ID</th>
                                            <th>举报内容</th>
                                            <th>举报者ID</th>
                                            <th>举报者昵称</th>
                                            <th>举报者电话</th>
                                            <th>被举报评论ID</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {
                                            this.props.reportreducer.filter(
                                                item => !(item.report2 !== 5)).map((item, index) => {
                                                    console.log(item)
                                                    return (
                                                        <tr>
                                                            <td>{index + 1}</td>
                                                            <td>{item.report_id}</td>
                                                            <td>{item.report_context}</td>
                                                            <td>{item.user_id}</td>
                                                            <td>{item.user_name}</td>
                                                            <td>{item.user_phone}</td>
                                                            <td>{item.report.report_id}</td>
                                                            <td>
                                                                <button className="solute"
                                                                    onClick={() => {
                                                                        const adminpwd = prompt('请输入管理员登录密码：')
                                                                        if (adminpwd) {
                                                                            this.props.dispatch(DelReport(item.report_id, adminpwd))
                                                                            Send_tim(item.user_phone, `您举报的评论<${item.report_context}>已经被处理`)
                                                                        }
                                                                        return false;
                                                                    }}
                                                                >已解决</button></td>
                                                        </tr>
                                                    )
                                                })
                                        }
                                    </tbody>
                                </table>
                            </div>
                            {/* 分页 */}
                            <GotoPage5 />
                        </div>
                    </Tabs>
                    <WhiteSpace />
                </div>
            </div>
        );
    }
}
const mapStateToProps = (state) => ({
    reportreducer: state.reportreducer,
    userreducer: state.userreducer,
    fruiterreducer: state.fruiterreducer,
    textreducer: state.textreducer
})
export default connect(mapStateToProps)(withRouter(Discuss));
